package com.iamteer.day14;

import java.io.IOException;
import java.io.StringWriter;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.SkipPageException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class DemoTag extends SimpleTagSupport{
	@Override
	public void doTag() throws JspException, IOException {
		//获取标签体内容
		JspFragment jspBody = this.getJspBody();
		
		//输出标签体内容
//		JspWriter out = this.getJspContext().getOut();
//		jspBody.invoke(out);
//		jspBody.invoke(null);	//效果等同以上两句
		
		//路过标签后的内容
//		throw new SkipPageException();
		
		//重复输出
//		for (int i = 0; i < 5; i++) {
//			jspBody.invoke(null);
//		}
		
		//改变标签体内容
		StringWriter sw = new StringWriter();	//创建临时容器
		jspBody.invoke(sw);						//获取内容
		String content = sw.toString();			//得到内容
		content = content.toUpperCase();		//改变内容
		this.getJspContext().getOut().write(content);	//输出
	}
}
